#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
int main(){
    int i = 100;
    // 创建进程
    pid_t pid;
    pid = fork();

    // 检查fork函数是否失败
    if(pid < 0){
        perror("fork failed");
        return 1;
    }

    // 子进程代码块
    if(pid == 0){
        i++;
        printf("i is %d\n", i);
        printf("I am child, child pid num is %d\n", getpid());
        return 0;
    }

    // 父进程代码块
    if(pid > 0){
        printf("I am parent, my pid num is %d\n", getpid());
        sleep(2);
        printf("i is %d\n", i);
        return 0;
    }
    return 0;
}